from typing import Annotated

from fastapi import Depends
from sqlalchemy import Engine
from sqlmodel import Session, create_engine

from config import settings

# 连接到数据库
engine = create_engine(settings.database_url, connect_args=settings.connect_args)


def get_engine() -> Engine:
    return engine


def get_session() -> Session:
    with Session(engine) as session:
        yield session


EngineDep = Annotated[Engine, Depends(get_engine)]
SessionDep = Annotated[Session, Depends(get_session)]
